<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>新增产品</title>
  <script>
    if(/http:/.test(location.href)) location.href = location.href.replace(/http:/, 'https:')
  </script>
  <script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/jquery"></script>
  <script src="__PUBLIC__/script/layer/layer.js"></script>
  <script src="__PUBLIC__/node_modules/datatables/media/js/jquery.dataTables.min.js"></script>
  <script src="__PUBLIC__/script/bootstrap-treeview-master/dist/bootstrap-treeview.min.js"></script>
  <script src="__PUBLIC__/script/tagEditor/jquery.tag-editor.min.js"></script>
  <script src="__PUBLIC__/script/tagEditor/jquery.caret.min.js"></script>
  <link rel="stylesheet" href="__PUBLIC__/style/base.css">
  <link rel="stylesheet" href="__PUBLIC__/script/tagEditor/jquery.tag-editor.css">
  <link rel="stylesheet" href="__PUBLIC__/script/bootstrap-treeview-master/dist/bootstrap-treeview.min.css">
  <link rel="stylesheet" href="__PUBLIC__/node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="__PUBLIC__/style/manage.css">
  <link rel="stylesheet" href="__PUBLIC__/style/manage_chanpin.css">
  <link rel="stylesheet" href="__PUBLIC__/style/add_chanpin.css">
</head>
<body>
  <div style='display:none;'>
    <!--
      基础信息删除{:U('Wxauthorise/del_cj_xinxi')}
      数据：jc_id(基础信息id)
      返回：code message
      code 1成功其余失败 message信息
     -->
     <input type="hidden" name="基础信息删除" id="URL4jichu" value="{:U('Wxauthorise/del_cj_xinxi')}">
     <!--
       核心信息删除{:U('Wxauthorise/del_cp')}
        数据：good_id(核心信息id)
        返回：code message
        code 1成功其余失败 message信息
      -->
     <input type="hidden" name="核心信息删除" id="URL4hexin" value="{:U('Wxauthorise/del_cp')}">
  </div>
  <div class="container-fluid">
    <div class="row">
      <header class="col-xs-6 col-md-2 account_name"><img class='img-responsive' src="__PUBLIC__/images/logo_long.jpg" alt=""></header>
      <div class="col-xs-12 col-md-12">
        <div class="row">

          <!-- 左侧栏 -->
         <div class="col-md-2 manage_nav_box">
            <iframe src="{:U('nav_1')}?local=chanpin_a" frameborder="0" width="100%" style="height:35rem;"></iframe>
            <!-- 账号选项 -->
            <div class="account_option">
              <a href="{:U('index/update_passwd')}" class="pass_mod">修改密码</a>
              <a href="{:U('index/loginout')}" class="sign_out">退出登录</a>
            </div>
            <!-- end 账号选型 -->
          </div>
          <!-- end 左侧栏 -->

          <!-- 右主体  -->
          <div class="col-md-10 col-md-10 messageBox">
            <div class="row border_bottom">
              <div class="col-xs-12 col-md-12 title">
                <span>添加产品基础信息</span><a href="#simple_table"><img id="add_simple_frame" src="__PUBLIC__/images/neiye/u138.png" alt="u138" title="添加基础信息"></a>
              </div>


              <form autocomplete="off" action="{:U('Bm_zongadd')}" id = 'simple_form' method='post'>
                <!-- fid -->
                <input type='hidden' name='type' value='{$fid}' id='simple_form1'>
                <!-- disabled掉的input不会出现在ajax的数组中 -->
                <input disabled type="text" id='get_new_pro_id' name='get_new_pro_id' value = "{:U('Wxauthorise/cp_add')}" style="display:none;">
                <!-- 获取联动渠道名称列表，post -->
                <input type="hidden" form='not_submit' name='POST中文名称' id='get_new_qudao_name_list' value="{:U('Wxauthorise/ajax_add_chanpin')} ">

                <div class="col-xs-12 col-md-12 simple_table">
                  <div class="main_table" id="simple_table">
                    <!-- 表头 -->
                    <div class="chanpin_simple_content">
                      <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">产品名称</span>
                      <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">渠道类型</span>
                      <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">渠道名称</span>
                      <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">包装名称</span>
                      <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">操作</span>
                    </div>
                    <!-- end 表头 -->

                    <!-- 表主体 -->
                    <ul class="chanpin_simple">
                      <!-- jq操作模板 -->
                      <li class="chanpin_simple_content" id="chanpin_simple_content" style="display:none;">
                        <!-- title -->
                        <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">
                          <if condition='$BMjc'>
                            <input type="text"  class = 'first_name'  name="simple[chanpin_name]" value="{$BMjc[0]['name']}" placeholder="产品名称" readonly >
                          <else/>
                            <input type="text"  class = 'first_name' value="" name="simple[chanpin_name]" placeholder="产品名称" >
                          </if>
                        </span>
                        <!-- end title -->
                        <!-- 渠道类别 -->
                        <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">
                          <select name="simple[qudao_type]" class = 'first_qudao'>
                            <option value="0" selected>请选择产品渠道类别</option>
                            <volist name='qudao_list' id="vo">
                              <option value="{$vo.qudao_id}">{$vo.qudao_type}</option>
                            </volist>
                          </select>
                        </span>
                        <!-- end 渠道类别 -->
                        <!-- 渠道名称 -->
                        <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">
                          <input type="text" class = 'first_qudao_name' name="simple[qudao_name]" placeholder="渠道名称 - 请先选择渠道类别" readonly>
                        </span>
                        <!-- 包装名称 -->
                        <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;"><input type="text" class = 'first_alt_name' name="simple[chanpin_alt_name]" placeholder="包装名称"></span>
                        <!-- 删除信息 -->
                        <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;"><img  class="deleteThisLine" src="__PUBLIC__/images/neiye/u324.png" alt="u324" style='height:2rem;cursor:pointer;'></span>
                      </li>
                      <!-- end jq操作模板 -->

                      <!-- 后端循环块 -->
                      <volist name='BMjc' id='vo'>
                         <li class="chanpin_simple_content chanpin_simple_content_php">
                          <input type='hidden' value='{$vo.id}' name='jc{$vo.id}[id]' class='debugID_test'>
                          <!-- TODO: 循环输出选择列表，记得.change() -->
                          <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">
                            <input type="text" class = 'first_name_2' name="jc{$vo.id}[chanpin_name]" placeholder="产品名称" value='{$vo.name}'>
                          </span>
                          <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;">
                            <input  class = 'first_qudao_2' type="text" style="display: none;" name="jc{$vo.id}[qudao_type]" value="{$vo.dtypename}">{$vo.dtypename|re_name}
                          </span>
                          <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;"><input type="text" name="jc{$vo.id}[qudao_name]" placeholder="渠道名称" value='{$vo.qudaoname}'></span>
                          <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;"><input type="text" name="jc{$vo.id}[chanpin_alt_name]" placeholder="包装名称" value='{$vo.bzname}'></span>
                          <!-- 删除信息 -->
                          <span style="display:inline-block;width:19%;font-size:1.5rem;text-align:center;line-height:2rem;"><img class="deleteThisLine" src="__PUBLIC__/images/neiye/u324.png" alt="u324" style='height:2rem;cursor:pointer;'></span>
                        </li>
                      </volist>
                      <!-- end 后端循环块 -->

                    </ul>
                    <!-- end 表主体 -->
                  </div>
                </div>
              </form>
            </div>
            <div class="row border_bottom adv_info">
              <div class="col-xs-12 col-md-12 title">
                <span>添加产品核心信息</span><a href="#adv_table"><img id="add_adv_frame" src="__PUBLIC__/images/neiye/u138.png" alt="u138" title="添加核心信息"></a>
              </div>
              <div class="col-xs-12 col-md-12 adv_table">
                <div class="main_table" id="adv_table">
                  <div class="chanpin_adv_content">
                    <span class="flex_chanpin_dalei" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">产品大类</span>
                    <span class="flex_chanpin_xiaolei" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">渠道小类</span>
                    <span class="flex_chanpin_xiaolei" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">产品名称</span>
                    <span class="flex_biaoqian_num" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">标签总数</span>
                    <span class="flex_lixi_percent" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">利息</span>
                    <span class="flex_edu" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">额度</span>
                    <span class="flex_preview" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">预览</span>
                    <span class="flex_setting" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">设置</span>
                    <span class="flex_delete" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">删除</span>
                  </div>
                  <ul class="chanpin_adv">
                    <li style = 'display:none' id="chanpin_adv_content" class="chanpin_adv_content">
                      <span class="flex_chanpin_dalei" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"></span>
                      <span class="flex_chanpin_xiaolei" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"></span>
                      <span class="flex_chanpin_xiaoming" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"><span class="chanpin_xiaoming"></span></span>
                      <span class="flex_biaoqian_num" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"><span class="biaoqian_num"></span></span>
                      <span class="flex_lixi_percent" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"><span class="lixi_percent"></span></span>
                      <span class="flex_edu" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"><span class="edu"></span></span>
                      <span class="flex_preview" style="display:block;text-align:center;width:5%;font-size:1.5rem;text-align:center;line-height:2rem;"><img src="__PUBLIC__/images/new_chanpin_popup/u93.png" alt="u93" style="height:1.5rem;"></span>
                      <span class="flex_setting" style="display:block;text-align:center;width:5%;font-size:1.5rem;text-align:center;line-height:2rem;"><a href="__PUBLIC__/add_adv_chanpin.html?12674"><img src="__PUBLIC__/images/dengluye/u41.png" alt="u41" style="height:1.5rem;"></a></span>
                      <span class="flex_delete" style="display:block;text-align:center;width:5%;font-size:1.5rem;text-align:center;line-height:2rem;"><img class="deleteThisLineAdvPro" src="__PUBLIC__/images/neiye/u324.png" alt="u324" style="height:1.5rem;"></span>
                    </li>
                    <volist name='info' id='vo'>
                      <li class="chanpin_adv_content chanpin_adv_content_from_php" data-id='{$vo.id}'>
                        <span class="flex_chanpin_dalei" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"><span class="chanpin_dalei">{$vo.name}</span></span>
                        <span class="flex_chanpin_xiaolei" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"><span class="chanpin_xiaolei" inori-data='xiaoleiVar{$key}'></span></span>
                        <span class="flex_chanpin_xiaoming" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;">{$vo.litter_name}<span class="chanpin_xiaoming"></span></span>
                        <span class="flex_biaoqian_num" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"><span class="biaoqian_num">{$vo.count}</span></span>
                        <span class="flex_lixi_percent" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"><span class="lixi_percent">{$vo.min_lx}%-{$vo.max_lx}%</span></span>
                        <span class="flex_edu" style="display:block;text-align:center;font-size:1.5rem;text-align:center;line-height:2rem;"><span class="edu">{$vo.min_ed}万-{$vo.max_ed}万</span></span>
                        <span class="flex_preview" style="display:block;text-align:center;width:5%;font-size:1.5rem;text-align:center;line-height:2rem;"><img src="__PUBLIC__/images/new_chanpin_popup/u93.png" alt="u93" style="height:1.8rem;"></span>
                        <span class="flex_setting" style="display:block;text-align:center;width:5%;font-size:1.5rem;text-align:center;line-height:2rem;"><a href="{:U('add_adv_chanpin',array('id'=>$vo[id],'did'=>$fid))}"><img src="__PUBLIC__/images/dengluye/u41.png" alt="u41" style="height:1.5rem;"></a></span>
                        <span class="flex_delete" style="display:block;text-align:center;width:5%;font-size:1.5rem;text-align:center;line-height:2rem;"><img class="deleteThisLineAdvPro" src="__PUBLIC__/images/neiye/u324.png" alt="u324" style="height:1.5rem;"></span>
                        <script>
                          $(document).ready(function () {
                            // 变量名字为php变量拼接
                            const xiaoleiVar{$key} = "{$vo.xiaolei}".split(',').filter((cur) => { if (cur.length > 0) { return true } })
                            let tempLine = ''
                            for (let i of xiaoleiVar{$key}) {
                              tempLine += String(`<span><span>${i}</span></span>`)
                            }
                            $(`.chanpin_xiaolei[inori-data='xiaoleiVar{$key}']`).append(tempLine)
                          })
                        </script>
                      </li>
                    </volist>
                  </ul>
                </div>
              </div>
            </div>
          </div>
          <!-- end 右主体 -->

         <div class="tijiao col-md-9 col-md-offset-2" style="display:none;">
            <div style="height:2rem;"></div>
            <div class="submit_all col-xs-5 col-md-2 col-md-offset-1"><input type="submit" value="提交" form="simple_form" style='width:100%;'></div>
            <!-- <div class="quxiao_back col-xs-5 col-xs-offset-5 col-md-2 col-md-offset-6"><input type="reset" value="清空" form="simple_form" style='width:100%;'></div> -->
          </div>
        </div>
      </div>
    </div>
  </div>
  <script id="sync_option">
    // 用于同步选项信息
    $(document).ready(function() {
      window.inori = []
      // 如果是等于0就是没有first_name_2元素，也就是后端没输出也没有第一项添加在前
      var first_simple = $('.first_name_2').length === 0
      // 如果文档初始时已经有的话，也就是有后端模板
      if (!first_simple) {
        $('.first_name_2:first').attr('class', 'first_name_1')
        $('.first_qudao_2:first').attr('class', 'first_qudao_1')

        $('.first_name_1').on('change', function () {
          var text = $(this).val()
          $.each($('.first_name_2'), function(){$(this).val(text)})
        })
        $('.first_qudao_1').on('change', function () {
          // ajax联动改变当前的右边渠道name
          console.log($(this).val())
        })
        // 手动触发一次，防止输入错误
        $('.first_name_1').change()
        // 储存第一条基础信息
        // localStorage.setItem(`baseName${location.href.match(/dID\/(\d{1,})/)[1]}`, `一个产品发生修改：${$(`.first_name_1`).val()}，可在登陆状态下访问 ${location.href} 查看。`)
        localStorage.clear()
        localStorage.setItem(`baseName${location.href.match(/dID\/(\d{1,})/)[1]}`, `一个产品发生修改：${$(`.first_name_1`).val()}。`)
      }

      // 基础信息
      $('#add_simple_frame').on('click', function () {

        var fid = $('#simple_form1').val();
        var user = {
          id:fid
        };
        var url = "{:U(cj_xinxi)}"
        $.ajax({
          type: 'post',
          url: url,
          data: user,
          beforeSend: function() {
            $('#add_simple_frame').css('visibility','hidden')
          },
          success:function(data){
            // #adv_table 包含在 .adv_info > .adv_table
            if ($('#adv_table').length > 0) {
              $('.adv_info > .title > span').text('请先提交基础信息')
              $('.adv_info > .title > a').remove()
              $('.adv_info > .adv_table').remove()
            }
            $('#add_simple_frame').css('visibility','visible')
            $('.tijiao').css('display', 'block')
            // alert(data);
            var dataArray  = data.split('|')
            $('#simple_form1').val(dataArray[0]);
            var debugID = dataArray[1]
            var hiddenIndex = document.createElement('input')
            hiddenIndex.setAttribute('name', `jc${debugID}[id]`)
            hiddenIndex.setAttribute('type', 'hidden')
            hiddenIndex.setAttribute('value', debugID)
            if ( first_simple ) {
              first_simple = !first_simple
              // 第一次改掉ID并留下，
              var liTemp = document.getElementById('chanpin_simple_content').cloneNode(true)
              hiddenIndex.className= 'debugID_test'
              liTemp.append(hiddenIndex)
              liTemp.id = 'chanpin_simple_content_first'
              liTemp.style = 'display:block;'

              var first_name = liTemp.getElementsByClassName('first_name')[0]
              var first_qudao = liTemp.getElementsByClassName('first_qudao')[0]
              var first_qudao_name = liTemp.getElementsByClassName('first_qudao_name')[0]
              var first_alt_name = liTemp.getElementsByClassName('first_alt_name')[0]

              first_name.className = 'first_name_1'
              first_qudao.className = 'first_qudao_1'
              first_qudao_name.className = 'first_qudao_name_1'
              first_alt_name.className = 'first_alt_name_1'

            } else {
              var liTemp = document.getElementById('chanpin_simple_content').cloneNode(true)
              liTemp.append(hiddenIndex)
              liTemp.style = 'display:block;'

              var first_name = liTemp.getElementsByClassName('first_name')[0]
              var first_qudao = liTemp.getElementsByClassName('first_qudao')[0]
              var first_qudao_name = liTemp.getElementsByClassName('first_qudao_name')[0]
              var first_alt_name = liTemp.getElementsByClassName('first_alt_name')[0]

              first_name.className = 'first_name_2'
              first_qudao.className = 'first_qudao_2'
              first_qudao_name.className = 'first_qudao_name_2'
              first_alt_name.className = 'first_alt_name_2'

              first_name.setAttribute('readonly', true)
              first_qudao.setAttribute('readonly', true)
              $(first_name).val($('.first_name_1').val())
              first_qudao.value = $('.first_qudao_1').val()
            }

            first_name.setAttribute('name', `jc${debugID}[chanpin_name]`)
            first_qudao.setAttribute('name', `jc${debugID}[qudao_type]`)
            first_qudao_name.setAttribute('name', `jc${debugID}[qudao_name]`)
            first_alt_name.setAttribute('name', `jc${debugID}[chanpin_alt_name]`)
            // $(first_qudao).on('change', function () {
            //   // 发生变化时改变旁边的option列表
            //   console.log($(this).val())
            // })

            first_qudao_name.value = ''
            first_alt_name.value = ''

            $('.chanpin_simple').append(liTemp)
            // 基础信息联动
            $(`[name='jc${debugID}[qudao_type]']`).on('change', function (evt) {
              const targetParentEle = $(evt.target).closest('.chanpin_simple_content')
              let qudaoNameEle = targetParentEle.find('span:eq(2) input')
              if (qudaoNameEle.length === 0) qudaoNameEle = targetParentEle.find('span:eq(2) select')
              qudaoNameEle.html(`<option value='null'>正在获取渠道列表，请稍候</option>`)
              let url = $('#get_new_qudao_name_list').val()
              /* 修改后的值 */
              let qudaoTypeVal = $(evt.target).val()
              /* 修改后的值对应中文 */
              let qudaoType = $(evt.target).find(`option[value="${qudaoTypeVal}"]`).text()
              let Name = qudaoNameEle.attr('name')
              let className = qudaoNameEle.attr('class') || 'php_qudao_name'

              if (qudaoType.length < 1) return
              let nameAjax = $.post(url, {qudao_type: qudaoType})
              nameAjax.done(function(data){
                let nameArr = []
                // if (String(typeof data).toLowerCase() === 'array') {
                  for(let e of data) {
                    nameArr.push({name: e.qudao_nick_name, value: e.qudao_id})
                  }
                // }
                let tempEle = `<select name="${Name}" class = '${className}'>`
                for(let item of nameArr) {
                  tempEle += `<option value="${item.name}">${item.name}</option>`
                }
                tempEle += `</select>`
                tempEle = $(tempEle)
                qudaoNameEle.replaceWith(tempEle)
              })
            })
            $(`[name='jc${debugID}[qudao_type]']`).change()

            $('.first_name_1').off('change')
            $('.first_name_1').on('change', function () {
              $.each($('.first_name_2'), function (inex, item) {
                $('.first_name_2').val($('.first_name_1').val())
              })
            })
            $('.deleteThisLine').each((index, item) => {
              if (index === 1) {
                $(item).off('click')
                $(item).css('visibility', 'hidden')
              } else {
                $(item).off('click')
                $(item).on('click', deleteThisLine)
                $(item).css('visibility', 'visible')
              }
            })
          }
        }).fail((err) => {
          alert('通信失败，请检查网络')
          throw new Error('请检查网络')
        })
      })
      // 核心信息
      $('#add_adv_frame').on('click', function () {
        var liTemp = document.getElementById('chanpin_adv_content').cloneNode(true)
        var urlBase = document.getElementById('get_new_pro_id').value
        var formData = $('#simple_form1').val();
        if(formData == ''){
          alert('请先添加基础信息！');
          return false;
        }
        var user = {
          id:formData,
          ab_id: $('.chanpin_adv_content_from_php:eq(0)').attr('data-id')
        };
        $.ajax({
          type: 'post',
          url: urlBase,
          data: user,
          beforeSend: function () {
            $('#add_adv_frame').css('visibility','hidden')
            layer.msg('加载中', {
              icon: 16,
              shade: 0.01
            })
          },
          success:function(data){
            $('#add_adv_frame').css('visibility','visible')
            // TODO: 添加首次判断，非首次才需要外加的参数
            var url = "{:U('Wxauthorise/add_adv_chanpin')}?order=update".replace(/(.+\w)(\.html)(.{0,})/, `\$1/id/${data}/did/${location.href.match(/\/dID\/(\d+)\./)[1]}\$2`)
            liTemp.getElementsByTagName('a')[0].href = url
            liTemp.id = ''
            // liTemp.style.display = 'flex'
            $('.chanpin_adv').append(liTemp)
            liTemp.getElementsByTagName('a')[0].click()
          }
        }).fail((err) => {
          $('#add_adv_frame').css('visibility','visible')
          alert('通信失败，请检查网络')
          throw new Error('请检查网络')
        })
        $('.deleteThisLineAdvPro').each((index, item) => {
          if (index === 1) {
            $(item).off('click')
            $(item).css('visibility', 'hidden')
          } else {
            $(item).off('click')
            $(item).on('click', deleteThisAdvLine)
            $(item).css('visibility', 'visible')
          }
        })
      })

      // 基础信息回填
      $('.chanpin_simple_content_php').each(function() {
        let qudaoTypeEle = $(this).find('span:eq(1) input')
        let qudaoNameEle = $(this).find('span:eq(2) input')
        let url = $('#get_new_qudao_name_list').val()
        /* 修改后的值 */
        let qudaoTypeVal = qudaoTypeEle.closest('span').text().replace(/[\s\r\n]/mg,'')
        /* 修改后的值对应中文 */
        let qudaoType = qudaoTypeVal
        let Name = qudaoNameEle.attr('name')
        let qudaoNameVal = qudaoNameEle.val()
        let className = qudaoNameEle.attr('class') || 'php_qudao_name'

        if (qudaoType.length < 1) return
        let nameAjax = $.post(url, {qudao_type: qudaoType})
        nameAjax.done(function(data){
          let nameArr = []
          // if (String(typeof data).toLowerCase() === 'array') {
            for(let e of data) {
              nameArr.push({name: e.qudao_nick_name, value: e.qudao_id})
            }
          // }
          let tempEle = `<select name="${Name}" class = '${className}'>`
          for(let item of nameArr) {
            if (item.name === qudaoNameVal) {
              tempEle += `<option value="${item.name}" select>${item.name}</option>`
            } else {
              tempEle += `<option value="${item.name}">${item.name}</option>`
            }

          }
          tempEle += `</select>`
          tempEle = $(tempEle)
          tempEle.val(qudaoNameVal)
          qudaoNameEle.replaceWith(tempEle)
        })
      })
      // 删除行
      if ($('.deleteThisLine').length === 0) {
        // 初始页面，在添加第一条之后才能删除
      } else {
        $('.deleteThisLine').each((index, item) => {
          if (index === 1) {
            $(item).off('click')
            $(item).css('visibility', 'hidden')
          } else {
            $(item).off('click')
            $(item).on('click', deleteThisLine)
            $(item).css('visibility', 'visible')
          }
        })
        $('.deleteThisLineAdvPro').each((index, item) => {
          if (index === 1) {
            $(item).off('click')
            $(item).css('visibility', 'hidden')
          } else {
            $(item).off('click')
            $(item).on('click', deleteThisAdvLine)
            $(item).css('visibility', 'visible')
          }
        })
      }
    })

    window.addEventListener('message', fromNav, false)
    function fromNav(event) {
      console.log(event.data.url)
      if (event.data.url.length && event.data.url.length > 1) {
        self.location = event.data.url
      }
    }
  </script>
  <!-- 工具函数 -->
  <script>
    // 删除基础信息
    function deleteThisLine (evt) {
      const parentEle = $(evt.target).closest('li')
      const id = parentEle.find('input[name*="id"]').val()
      const url = $('#URL4jichu').val()
      $.ajax(url, {
        method: 'post',
        data: {jc_id: id}
      }).done((data) => {
        if( String(data.code) === '1') {
          alert('删除成功')
          parentEle.remove()
        } else {
          alert(`删除失败，服务器返回：${data.message}`)
        }
      }).fail((err) => {
        alert('网络连接测试失败！请检查网络')
      })
    }
    // 删除高级信息
    function deleteThisAdvLine (evt) {
      const parentEle = $(evt.target).closest('li')
      const id = parentEle.find('.flex_setting a').attr('href').match(/\/id\/(\d{1,})\//)[1]
      const url = $('#URL4hexin').val()
      $.ajax(url, {
        method: 'post',
        data: {good_id: id}
      }).done((data) => {
        if( String(data.code) === '1') {
          alert('删除成功')
          parentEle.remove()
        } else {
          alert(`删除失败，服务器返回：${data.message}`)
        }
      }).fail((err) => {
        alert('网络连接测试失败！请检查网络')
      })
    }
    // 在页面还没有基础信息的时候隐藏页面核心信息
    if ( ! /\/dID\/\d{1,}/.test(location.href) ) {
      $('.adv_info').remove()
    }
  </script>
</body>
</html>
